/**
 * Created by HuyNguyen on 3/19/14.
 */

var productDetailWeb = function() {
        var tab =  $('#tabs a'),
            $window = $(window),
            $flexSlider = $("#content #related_pro"),
            flexSlider;
    // change style of list show product
    var initTab = function(){
        $(tab).tabs();
    }

    // get grid size
    var getGridSize = function (){
        return ($window.innerWidth() < 320) ? 1 :
            ($window.innerWidth() < 600) ? 2 :
                ($window.innerWidth() < 800) ? 3 :
                    ($window.innerWidth() < 900) ? 4 : 5;
    }

    /* Initialization slide */
    var initSlider = function () {

        $flexSlider.flexslider({
            animation: "slide",
            animationLoop: false,
            slideshow: false,
            itemWidth: 210,
            minItems: getGridSize(), // use function to pull in initial value
            maxItems: getGridSize(), // use function to pull in initial value
            start: function (slider) {
                flexSlider = slider;
            }
        });
    };
    return {
        init: function () {
           // setupProduct();
            initTab();
            initSlider();
        },
        resizeItem : function(){
            var gridSize = getGridSize();
            flexSlider.vars.minItems = gridSize;
            flexSlider.vars.maxItems = gridSize;
        }

    };
}();

/* Initialize WebApp when page loads */
$(function(){
    productDetailWeb.init();
    $(window).resize(function(){
        productDetailWeb.resizeItem();

    });

    $(window).load(function(){
        productDetailWeb.initSlider();
    });

    $(window).on("orientationchange",function(){
        productDetailWeb.resizeItem();
    });

});